
var ValidationRules =ValidationRules || {};

ValidationRules.addRules=function(){
    $.each(ValidationRules.Rules,function(index,value){
        if($(value.elementName).length>0){
            ValidationRules.addRule(value.elementName,value.validators,value.errorMessage,value.params);

        }
        else{

        }
    });

}
ValidationRules.addRule=function(elementSelector,validators,errorMessagesArray,ParamArray){
    var ruleObject={ };
    var messages={ };
    $.each(validators,function(index,value){
        ruleObject[value]=ParamArray[index];
        messages[value]=errorMessagesArray[index];
    });
    ruleObject["messages"]=messages;
    $(elementSelector).each(function(index){
        $(this).rules('add',ruleObject);
    });
};

ValidationRules.removeRule=function(elementSelector,validationName){
    $(elementSelector).promise().done(function(){
        $(this).rules('remove',validationName);
        return true;
    });
};

